

import android.content.Context;
import android.media.MediaPlayer;

import android.content.Context;
import android.media.MediaPlayer;
import android.util.Log;

public class AudioPlayer{
	private Context c;	
	private int fileId;
	private MediaPlayer mPlayer;
	 private static final String TAG = "AudioPlayerTest";

	public AudioPlayer (Context c, int resid) {
	    this.c = c;
	    this.fileId = resid;
	    mPlayer = MediaPlayer.create(c, fileId);
	}
	
	public void playAudio () {	    
	    int duration = getDuration();
	    long startTime = System.currentTimeMillis();
	   
	    try {                                
            mPlayer.start();            
           
        } catch (Exception e) {
            Log.e(TAG, "error: " + e.getMessage(), e);}
        }

	public int getDuration()
	{
		return mPlayer.getDuration();	
	}
	
	public void stopAudio()
	{
		if (mPlayer != null) {
            mPlayer.release();
            mPlayer = null;
        }

	}
}